class FriendController {
    constructor() {
         Laya.timer.loop(Cfg.WatcherHeartSpace, this, this.WatcherHeart);
    }

    //进入好友农场
    EenterFriendFarm(dbid, fieldNum, fieldList, weatherId, shieldIsOpen, shieldEndTime) {
        let friendInfo = KBEngine.app.player().GetFriendInfo(dbid);
        if (!friendInfo) {
            return;
        }

        //设置积分、农作物、天气等数据
        PlayerModel.SetFriendDbid(dbid);
        PlayerModel.SetAvatarUrl(friendInfo.avatarUrl);
        PlayerModel.SetScore(friendInfo.score);
        PlayerModel.SetNickName(friendInfo.nickName);
        FieldModel.SetFieldNum(fieldNum);
        FieldModel.SetFieldList(fieldList);
        WeatherModel.SetWeatherId(weatherId);
        ShieldModel.SetIsOpen(shieldIsOpen);
        ShieldModel.SetEndTime(shieldEndTime);

        FieldModel.InitStage();
        CtrlManager.GetCtrl(CtrlNames.Field).SetField();
        CtrlManager.GetCtrl(CtrlNames.Field).SetWeather();
        CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();

        //处理界面、按钮等
        Game.viewFarm.EenterFriendFarm();
    }

    //离开好友农场
    LevelFriendFarm() {
        Game.viewFarm.LevelFriendFarm();

        PlayerModel.ClearFriendDbid();
        PlayerModel.SetAvatarUrl(KBEngine.app.player().avatarUrl);
        PlayerModel.SetScore(KBEngine.app.player().score);
        PlayerModel.SetNickName(KBEngine.app.player().nickName);
        FieldModel.SetFieldNum(KBEngine.app.player().fieldNum);
        FieldModel.SetFieldList(KBEngine.app.player().fieldList);
        WeatherModel.SetWeatherId(KBEngine.app.player().weatherId);
        ShieldModel.SetIsOpen(KBEngine.app.player().shieldIsOpen);
        ShieldModel.SetEndTime(KBEngine.app.player().shieldEndTime);

        FieldModel.InitStage();
        CtrlManager.GetCtrl(CtrlNames.Field).SetField();
        CtrlManager.GetCtrl(CtrlNames.Player).SetScore();
        CtrlManager.GetCtrl(CtrlNames.Field).SetWeather();
        CtrlManager.GetCtrl(CtrlNames.Shield).SetShield();

        CtrlManager.GetCtrl(CtrlNames.Mail).setBubble();
        CtrlManager.GetCtrl(CtrlNames.Task).setBubble();
        CtrlManager.GetCtrl(CtrlNames.Darw).setBubble();
    }

    WatcherHeart() {
        if (!PlayerModel.IsSelfFarm()) {
            //如果当前不是在自己农场，则发送观察者心跳
            ComFun.BaseCall("watcherHeart", PlayerModel.GetFriendDbid());
        }
    }
}